package com.sip.stream.utils.zfy.handler;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.sip.stream.gbstack.GS28181SDK;
import com.sip.stream.gbstack.GS28181SDKConfig;
import com.sip.stream.helper.GS28181Helper;
import com.sip.stream.utils.zfy.ZFYPlatformRemoteText;

import io.reactivex.Single;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.observers.DisposableObserver;
import java.text.SimpleDateFormat;
import java.util.Map;

public abstract class IGB28181TranHandler {

    protected final SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    private CompositeDisposable compositeDisposable;

    public abstract void afterRegisterSuccess();

    public abstract Single<Boolean> bindUser(String str, String str2);


    public void handupInviteVideo() {
    }

    public abstract int onTransDataNotify(String str, int i);

    public abstract void postAlarmTypeToPlatform(String type, String message);

    public abstract void postDeviceSOS();

    public abstract Single<Boolean> postRemoteText(ZFYPlatformRemoteText zFYPlatformRemoteText);

    public void reportAction(String str, String str2) {
    }

    public Single<Boolean> modifyPassword(String str, String str2, String str3) {
        return Single.error(new Exception("not support"));
    }

    public Single<Boolean> deviceUnbindNotify(String str) {
        return Single.error(new Exception("not support"));
    }

    public Single<String> queryUpgradePackageQuery() {
        return Single.error(new Exception("not support"));
    }

    public void release() {
        CompositeDisposable compositeDisposable = this.compositeDisposable;
        if (compositeDisposable != null) {
            compositeDisposable.dispose();
            this.compositeDisposable = null;
        }
    }

    public GS28181SDKConfig getConfig() {
        return GS28181SDK.getInstance().getConfig();
    }

    public Disposable addDisposable(Disposable disposable) {
        if (this.compositeDisposable == null) {
            this.compositeDisposable = new CompositeDisposable();
        }
        this.compositeDisposable.add(disposable);
        return disposable;
    }

    public DisposableObserver addDisposableObserver(DisposableObserver disposableObserver) {
        if (this.compositeDisposable == null) {
            this.compositeDisposable = new CompositeDisposable();
        }
        this.compositeDisposable.add(disposableObserver);
        return disposableObserver;
    }

    public String createTranData(JsonObject jsonObject) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
            String key = entry.getKey();
            sb.append("<" + key + ">");
            JsonElement value = entry.getValue();
            if (!value.isJsonNull()) {
                if (value.isJsonObject()) {
                    sb.append(createTranData(value.getAsJsonObject()));
                } else {
                    sb.append(value.getAsString());
                }
                sb.append("</" + key + ">");
            }
        }
        return sb.toString();
    }

    public void sendTransData(String str) {
        GS28181Helper.getInstance().postTranData(str);
    }

    public void responseTransData(String str, int i) {
        GS28181SDK.getInstance().responseTransData(str, i);
    }

    public void sendTransDataGateway(String str) {
        GS28181Helper.getInstance().postTransDataGateway(str);
    }

    public Single<Boolean> startFaceBind(String str) {
        return Single.error(new Exception("not support"));
    }
}
